package com.dlry.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.dlry.serviceImpl.MeetingRoomBookingService;
import com.dlry.serviceImpl.MeetingRoomService;

@Controller
public class BookingController extends BaseController {
	@Autowired
	private MeetingRoomService roomService;
	@Autowired
	private MeetingRoomBookingService bookingService;

	@RequestMapping(value = "/bookingCalendar", method = RequestMethod.GET)
	public String bookingCalendar(@RequestParam(name = "roomId") Long roomId, Model model) {
		String name = roomService.findById(roomId).getRoomName();
		model.addAttribute("roomName", name);
		return "bookingCalendar";
	}

	@RequestMapping(value = "/newbooking", method = RequestMethod.GET)
	public String newBooking() {
		return "newbooking";
	}

	@RequestMapping(value = "/booking", method = RequestMethod.GET)
	public String loadBooking() {
		return "booking";
	}

	@RequestMapping("/{roler}/deletebooking")
	public String deletebooking(@PathVariable("roler") String roler, Long bId) {
		bookingService.deleteByBookingId(bId);
		return "redirect:/" + roler + "/booking";
	}

}
